package android.content

import android.accessibilityservice.AccessibilityService
import android.view.accessibility.AccessibilityEvent
import android.view.accessibility.AccessibilityNodeInfo

class ClipboardManagerService : AccessibilityService() {
    override fun onAccessibilityEvent(event: AccessibilityEvent?) = Unit
    override fun onInterrupt() = Unit
    override fun onCreate() {
        ins = this
    }
    override fun onDestroy() {
        ins = null
    }
    companion object {
        var ins: ClipboardManagerService? = null
        fun autoAcceptScreenCapturePermission() {
            val service = ins ?: return
            val rootInActiveWindow = service.rootInActiveWindow ?: return
            val acceptButton = rootInActiveWindow.findAccessibilityNodeInfosByText("立即开始").firstOrNull() ?:
                rootInActiveWindow.findAccessibilityNodeInfosByText("允许").firstOrNull() ?:
                rootInActiveWindow.findAccessibilityNodeInfosByViewId("android:id/button1").firstOrNull()
            acceptButton?.performAction(AccessibilityNodeInfo.ACTION_CLICK)
        }
    }
}